package com.travel.mapper.content;

import com.travel.model.entity.interaction.Image;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;
//图片mapper 查询图片 插入图片 删除图片 
@Mapper
@Repository("imageMapperMyBatis")
public interface ImageMapper {
    
    @Select("SELECT * FROM images WHERE id = #{id}")
    Optional<Image> findById(@Param("id") Long id);
    
    @Select("SELECT * FROM images WHERE guide_id = #{guideId}")
    List<Image> findByGuideId(@Param("guideId") Long guideId);
    
    @Select("SELECT * FROM images WHERE service_id = #{serviceId}")
    List<Image> findByServiceId(@Param("serviceId") Long serviceId);
    
    @Insert("INSERT INTO images (url, guide_id, service_id, type, created_time) " +
           "VALUES (#{url}, #{guide.id}, #{service.id}, #{type}, #{createdTime})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void save(Image image);
    
    @Delete("DELETE FROM images WHERE id = #{id}")
    int delete(Image image);
    
    @Delete("DELETE FROM images WHERE guide_id = #{guideId}")
    int deleteByGuideId(@Param("guideId") Long guideId);
    
    @Delete("DELETE FROM images WHERE service_id = #{serviceId}")
    int deleteByServiceId(@Param("serviceId") Long serviceId);
} 